<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="java.io.BufferedInputStream"%>
<%@page import="java.io.File"%>
<%@page import="java.io.FileInputStream"%>
<%@page import="java.io.OutputStream"%>
<%@page import="org.apache.struts2.ServletActionContext"%>
<%
int col = Integer.parseInt(request.getParameter("TILECOL").toString());
int row = Integer.parseInt(request.getParameter("TILEROW").toString());
int level = Integer.parseInt(request.getParameter("TILEMATRIX").toString());
level = level+1;
///////2的level次方
int r_tmp = 1;
for(int i=0;i<level;i++){
	r_tmp =2*r_tmp;
}
////////
int r = r_tmp-1-row;
//row = row-1;
String getFilePath = request.getSession().getServletContext().getRealPath("/");
String newFilePath = getFilePath + "all\\IMG"+level+"\\Row"+r+"\\"+r+"_"+col+".jpg";
System.out.println(newFilePath);
File newFile = new File(newFilePath);
byte[] buffer = null;
BufferedInputStream bf = null;
if (!newFile.exists()) {
	newFilePath = getFilePath+"image\\mapgis.jpg";
}

bf = new BufferedInputStream(new FileInputStream(
		newFilePath));
buffer = new byte[bf.available()];
// 读入缓存
bf.read(buffer);
// 关闭文件
bf.close();
response.addHeader("Content-Disposition",
		"attachment; filename=file.png");
response.setContentType("images/png");
response.setHeader("Content-Length", String.valueOf(buffer.length));
OutputStream output = response.getOutputStream();
output.write(buffer);
// 关闭输入输出流
output.close();
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>My JSP 'MyJsp.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
    This is my JSP page. <br>
  </body>
</html>
